package com.jctrip.hotel.source.xxl.hmein.thread;

import org.apache.commons.lang.StringUtils;

import com.jctrip.hotel.common.constant.RedisKeyConstant;
import com.jctrip.hotel.common.context.BeanContext;
import com.jctrip.hotel.common.util.RedisUtil;
import com.jctrip.hotel.source.service.hmein.HmeinTaskService;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author henry
 * @Date 2023/6/3 17:33
 * @Description
 */
@Slf4j
public class SyncHmeinHotelIdTaskThread implements Runnable {
    private final String appId;


    public SyncHmeinHotelIdTaskThread(String appId) {
        this.appId = appId;
    }

    @Override
    public void run() {
        RedisUtil redisUtil = BeanContext.getApplicationContext().getBean(RedisUtil.class);
        HmeinTaskService hmeinTaskService = BeanContext.getApplicationContext().getBean(HmeinTaskService.class);
        while (redisUtil.lGetListSize(RedisKeyConstant.HOTEL_MAIN_HMEIN_HOTELID_LIST) > 0) {
            try {
                String hotelId = (String) redisUtil.rightPop(RedisKeyConstant.HOTEL_MAIN_HMEIN_HOTELID_LIST);
                if (StringUtils.isBlank(hotelId)) {
                    continue;
                }

                hmeinTaskService.syncHmeinHotelIdListTask(appId, hotelId);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }


    }
}
